package com.woniu.bh.beautysalon.client;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @version: V1.0
 * @author: Xbao
 * @className: TokenClient
 * @packageName: com.woniu.bh.backstage.client
 * @description: token拦截器
 * @data: 2020-10-14 22:19
 */
@Component
public class TokenClient implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        System.out.println("拦截token");
        ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        String token = attributes.getRequest().getHeader("X-Token");
        if(StringUtils.isEmpty(token)){
            requestTemplate.header("X-Token",token);
        }
    }
}
